package annotation;

import org.junit.Test;

import java.lang.reflect.Field;

/**
 * @author com.ymy.hadoop
 * @date 2018/12/15 15:07
 */
public class Annotation {

    @Test
    public void test03()throws Exception{
        Class<?> clazz = Class.forName("annotation.Animal");
        java.lang.annotation.Annotation[] annotations = clazz.getAnnotations();
        for (java.lang.annotation.Annotation annotation : annotations){
            System.out.println(annotation);
        }
    }

    @Test
    public void test02() throws Exception {
        Class<?> clazz = Class.forName("annotation.Animal");
        Field[] fields = clazz.getDeclaredFields();
        for (Field field:fields){
            RZFiled rzFiled = field.getAnnotation(RZFiled.class);
            System.out.println(rzFiled);
            System.out.println("---------------");
            if (rzFiled != null){
                System.out.println(field.getName() + " " + rzFiled.value());
            }
        }
    }

    @Test
    public void test01() throws Exception {
        Class<?> clazz = Class.forName("annotation.Animal");
        System.out.println(clazz.isAnnotation());
        System.out.println(clazz.isAnnotationPresent(RZBean.class));
        RZBean rzBean = clazz.getAnnotation(RZBean.class);
        if (rzBean != null){
            System.out.println(rzBean.table() + ":" + rzBean.from() + rzBean.annotationType());
        }
    }
}
